﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FAP.CaptchaCenter
{
    public class CaptchaClient
    {
        private static TcpClientSample m_client  = new TcpClientSample();

        //public delegate void ReceviceCaptchaHandeler(string _strCaptcha);

        public static event ReceviceCaptchaHandeler OnReceiveClientCaptcha = null;

        public static void SendCaptcha(string _strCaptcha)
        {
            if (OnReceiveClientCaptcha == null)
                throw new Exception("The OnRecevice function not set");

            if (m_client.isRun==false)
            {
                m_client.OnReceiveCaptcha += m_client_OnReceiveCaptcha;
                m_client.Connect();
            }
            var temp = Encoding.Unicode.GetBytes(_strCaptcha);
            m_client.ns.Write(temp, 0, temp.Length);
            m_client.ns.Flush();

            //m_client.ns.Close();
        }

        static void m_client_OnReceiveCaptcha(string _strCaptcha)
        {
            if (OnReceiveClientCaptcha != null)
                OnReceiveClientCaptcha(_strCaptcha);
        }


    }
}
